package app.modules.security.util.conversion;

import app.modules.common.annotation.ConvertFrom;
import app.modules.common.annotation.ConvertTo;
import app.modules.security.dto.web.permission.WebPermissionDTO;
import jasmine.framework.common.util.CollectionUtil;
import jasmine.framework.common.util.MapperUtil;
import jasmine.security.rbac.model.SecPermission;

import java.util.Collection;
import java.util.Collections;
import java.util.List;

/**
 * @author mh.z
 */
public class PermissionConvertUtil {

    @ConvertFrom(SecPermission.class)
    @ConvertTo(WebPermissionDTO.class)
    public static WebPermissionDTO secPermission2WebPermissionDTO(SecPermission secPermission) {
        if (secPermission == null) {
            return null;
        }

        return MapperUtil.mapTo(secPermission, WebPermissionDTO.class);
    }

    @ConvertFrom(SecPermission.class)
    @ConvertTo(WebPermissionDTO.class)
    public static List<WebPermissionDTO> secPermission2WebPermissionDTO(Collection<SecPermission> secPermissions) {
        if (CollectionUtil.isEmpty(secPermissions)) {
            return Collections.emptyList();
        }

        return MapperUtil.mapToList(secPermissions, WebPermissionDTO.class);
    }

}
